<?php

namespace app\server;

use Ip2Region;

class IpServer
{
    /**
     * 获取客户端IP
     * @return array IP信息
     */
    public function getClientIp() {
        $remote_addr = getenv('REMOTE_ADDR');
        $http_client_ip = getenv('HTTP_CLIENT_IP');
        $http_x_forwarded_for = getenv('HTTP_X_FORWARDED_FOR');
        $http_via = getenv('HTTP_VIA');
        $ip_addr = array(
            'remote_addr' => $remote_addr ? $remote_addr : '',
            'http_client_ip' => $http_client_ip ? $http_client_ip : '',
            'http_x_forwarded_for' => $http_x_forwarded_for ? $http_x_forwarded_for : '',
            'http_via' => $http_via ? $http_via : ''
        );
        return $ip_addr;
    }
    /**
     * 获取客户端IP对应的地区
     * @return array 地区信息
     */
    public function getRegion() {
        $ip_addr = $this->getClientIp();
//        $ip_addr = '163.177.151.110';
//        $ip2region = new Ip2Region();
//        $result= $ip2region->btreeSearch($ip_addr);
//        $ip_addr['region'] = $result['region'];
//        if ($ip_addr['remote_addr'] == '127.0.0.1') {
//            $ip_addr['region'] = '中国|0|福建|厦门|电信';
//        }
        $ip_addr['region'] = '中国|0|福建|未知|未知';
        return $ip_addr;
    }


}
?>
